﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace XboxShmup
{
   public class BackGround
    {
       public  Texture2D texture;
       public  Vector2[] positions;
       public   int speed;

        public void Initialize(ContentManager content ,String texturePath, int ScreenWidth, int speed)
        {
            texture = content.Load<Texture2D>(texturePath);
            this.speed = speed;
            positions = new Vector2[ScreenWidth / texture.Width + 1];
            for (int i = 0; i < positions.Length; i++)
            { 
                positions[1] = new Vector2(i * texture.Width, 0);
            }
        }
        public void Update()
        {
            for (int i = 0; i < positions.Length; i++)
            {
                positions[i].X += speed;
                if (speed <= 0)
                {
                    if (positions[i].X <= -texture.Width)
                    {
                        positions[i].X = texture.Width * (positions.Length - 1);
                    }
                }

                else
                {
                    if (positions[i].X >= texture.Width * (positions.Length - 1))
                    {
                        positions[i].X = -texture.Width;
                    }
                }
            }
        }
        public void Draw(SpriteBatch spriteBatch)
        {
            for (int i = 0; i < positions.Length; i++)
            {
                spriteBatch.Draw(texture, positions[i], Color.White);
            }
 
        }
    }
}
